package com.txcb.lib.base.view.weigit;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.appcompat.widget.AppCompatImageView;

import com.txcb.lib.base.R;


/**
 * author lambert on 2019-11-26
 */
public class TabIndicatorView extends RelativeLayout {

    private AppCompatImageView mImgIcon;



    int iconSelect = -1;
    String title = "";
    int iconWith;
    int titleColor = -1;
    private boolean mSelected;

    public TabIndicatorView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

    }

    public TabIndicatorView(Context context) {
        this(context, null);

        init();
    }

    public TabIndicatorView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TabIndicatorView);
        iconSelect = ta.getResourceId(R.styleable.TabIndicatorView_tabIcon, -1);
        title = ta.getString(R.styleable.TabIndicatorView_tabTitle);
        titleColor = ta.getResourceId(R.styleable.TabIndicatorView_tabColor, -1);
        iconWith = ta.getResourceId(R.styleable.TabIndicatorView_tabIconWidth,50);

        init();
    }

    /**
     * 初始化
     */
    private void init() {


        View.inflate(getContext(), R.layout.layout_tab_indicator, this);

        mImgIcon = findViewById(R.id.tab_img_icon);



//        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mImgIcon.getLayoutParams();
//        layoutParams.width = iconWith;
//        layoutParams.height = iconWith;
//
//        mImgIcon.setLayoutParams(layoutParams);
        mImgIcon.setImageDrawable(getContext().getResources().getDrawable(iconSelect));

    }


    /**
     * 设置选中
     */
    public void setTabSelected(boolean selected) {
        mSelected = selected;
        mImgIcon.setSelected(selected);



    }

    /**
     * 获得选中项
     *
     * @return
     */
    public boolean isTabSelected() {
        return mSelected;
    }
}
